package com.tangcco.lockwell.service.impl;

import com.tangcco.lockwell.domain.TextContent;
import com.tangcco.lockwell.repository.BaseMapper;
import com.tangcco.lockwell.repository.TextContentMapper;
import com.tangcco.lockwell.service.TextContentService;
import com.tangcco.lockwell.viewmodel.admin.textContent.TextContentPageVM;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

@Service
public class TextContentServiceImpl extends BaseServiceImpl<TextContent> implements TextContentService {
    @Resource
    private final TextContentMapper textContentMapper;

    public TextContentServiceImpl(BaseMapper<TextContent> baseMapper, TextContentMapper textContentMapper) {
        super(baseMapper);
        this.textContentMapper = textContentMapper;
    }

    //查询所有文档  分页查询
    @Override
    public List<TextContent> selectAllTextContent(TextContentPageVM requestVM) {
        Integer pageIndex = requestVM.getPageIndex();
        if (pageIndex != null) {
            pageIndex = (pageIndex - 1) * requestVM.getPageSize();
            requestVM.setPageIndex(pageIndex);
        }
        return textContentMapper.selectAllTextContent(requestVM);
    }

    //根据文档内容进行文档查询
    @Override
    public List<TextContent> selectTextContentByContent(String content) {
        return textContentMapper.selectTextContentByContent(content);
    }

    //删除所有修改过的文档
    @Override
    public int deleteByModifyTime() {
        return textContentMapper.deleteByModifyTime();
    }

    //添加
    @Override
    public int insert(TextContent record) {
        return super.insert(record);
    }
    //根据Id查询文档
    @Override
    public TextContent selectById(Integer id) {
        return super.selectById(id);
    }
    //删除
    @Override
    public int deleteById(Integer id) {
        return super.deleteById(id);
    }
    //修改
    @Override
    public int updateById(TextContent record) {
        return super.updateById(record);
    }
    /**
     * 查询content json中的子节点
     * @param id
     * @return
     */
    @Override
    public String selectChildContentByName(Integer id, String name) {
       return textContentMapper.selectChildContentByName(id,name);
    }
}
